import { asyncRouter, constantRoutes } from '@/router'
const state = {
  routes: []
}
const mutations = {
  setRoutes(state, date) {
    state.routes = [...constantRoutes, ...date]
  }
}
const actions = {
  filterRouter(store, menus) {
    // 根据用户的权限列表(调用时传进来)
    // 动态路由的数组
    // 一起筛选的出有权限的路由列表
    const routers = asyncRouter.filter(el => menus.includes(el.name))
    console.log(routers)
    store.commit('setRoutes', routers)
    return routers
  }
}

export default {
  namespaced: true,
  state,
  mutations,
  actions
}
